bitkeeper revision 1.1466.1.1 (428cceb2sTCzL9rItLSMlnmH9XrnTQ)
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Thu, 19 May 2005 17:36:50 +0000 (17:36 +0000)
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Thu, 19 May 2005 17:36:50 +0000 (17:36 +0000)
Ensure correct alignment of CPU0 stack -- it must be aligned on a
2^STACK_ORDER page boundary. This requirement is now also checked
at run-time, and a clear fatal error given if it is not satisfied.
This bug affected both x86/32 and x86/64.
Signed-off-by: Keir Fraser <keir@xensource.com>
xen/arch/x86/boot/x86_32.S
xen/arch/x86/boot/x86_64.S
xen/arch/x86/setup.c

index 74edbe1ebf9a699045980ba38efa464296f97e51..9f7580ab98a9f3cd1376bdfb4d6494d0a16ea0a2 100644 (file)
@@ -212,9 +212,13 @@ ENTRY(gdt_table)
         .fill 2*NR_CPUS,8,0          /* space for TSS and LDT per CPU    */
 
         .org 0x2000
-ENTRY(idle_pg_table) # Initial page directory is 4kB
-        .org 0x3000
+/* Maximum STACK_ORDER for x86/32 is 1. We must therefore ensure that the */
+/* CPU0 stack is aligned on an even page boundary!                        */
 ENTRY(cpu0_stack)
-        .org 0x3000 + STACK_SIZE
+
+        .org 0x2000 + STACK_SIZE
+ENTRY(idle_pg_table)
+
+        .org 0x2000 + STACK_SIZE + PAGE_SIZE
 ENTRY(stext)
 ENTRY(_stext)
index 4be1c0684e012ac38b49ba4cd9a15ae1acc87ad7..a2b2410ae9ba616cd56ee9b567aa1be8d2f1ded1 100644 (file)
@@ -243,8 +243,13 @@ ENTRY(idle_pg_table_4)
 ENTRY(idle_pg_table_l3)
         .quad idle_pg_table_l2 - __PAGE_OFFSET + 7
 
-/* Initial PDE -- level-2 page table. Maps first 64MB physical memory. */
         .org 0x4000
+/* Maximum STACK_ORDER for x86/64 is 2. We must therefore ensure that the */
+/* CPU0 stack is aligned on a 4-page boundary.                            */
+ENTRY(cpu0_stack)
+
+/* Initial PDE -- level-2 page table. Maps first 64MB physical memory. */
+        .org 0x4000 + STACK_SIZE
 ENTRY(idle_pg_table_l2)
         .macro identmap from=0, count=32
         .if \count-1
@@ -256,10 +261,7 @@ ENTRY(idle_pg_table_l2)
         .endm
         identmap /* Too orangey for crows :-) */
 
-        .org 0x5000
-ENTRY(cpu0_stack)
-
-        .org 0x5000 + STACK_SIZE
+        .org 0x4000 + STACK_SIZE + PAGE_SIZE
         .code64
 ENTRY(stext)
 ENTRY(_stext)
index b30df4de15c3e3e963dca233eaf659f037c84fd3..ee5c915d06c38e030bd50bbb3561c712ab07ff97 100644 (file)
@@ -69,6 +69,8 @@ extern void ac_timer_init(void);
 extern void initialize_keytable();
 extern int do_timer_lists_from_pit;
 
+extern unsigned long cpu0_stack[];
+
 struct cpuinfo_x86 boot_cpu_data = { 0, 0, 0, 0, -1 };
 
 #if defined(CONFIG_X86_64)
@@ -381,11 +383,8 @@ static void __init do_initcalls(void)
 
 static void __init start_of_day(void)
 {
-#ifdef MEMORY_GUARD
     /* Unmap the first page of CPU0's stack. */
-    extern unsigned long cpu0_stack[];
     memguard_guard_stack(cpu0_stack);
-#endif
 
     open_softirq(NEW_TLBFLUSH_CLOCK_PERIOD_SOFTIRQ, new_tlbflush_clock_period);
 
@@ -469,6 +468,8 @@ static void __init start_of_day(void)
 #endif
 }
 
+#define EARLY_FAIL() for ( ; ; ) __asm__ __volatile__ ( "hlt" )
+
 void __init __start_xen(multiboot_info_t *mbi)
 {
     char *cmdline;
@@ -495,7 +496,13 @@ void __init __start_xen(multiboot_info_t *mbi)
     if ( !(mbi->flags & MBI_MODULES) || (mbi->mods_count == 0) )
     {
         printk("FATAL ERROR: Require at least one Multiboot module.\n");
-        for ( ; ; ) ;
+        EARLY_FAIL();
+    }
+
+    if ( ((unsigned long)cpu0_stack & (STACK_SIZE-1)) != 0 )
+    {
+        printk("FATAL ERROR: Misaligned CPU0 stack.\n");
+        EARLY_FAIL();
     }
 
     xenheap_phys_end = opt_xenheap_megabytes << 20;